package battle
{
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	
	public class Character extends BaseObject
	{
		public static const FRAMES_PER_DIRECTION:int = 4;
		
		public static const DIRECTION_NUM:int = 4;
		
		public static const DIRECTION_LEFT:int = 1;
		
		public static const DIRECTION_RIGHT:int = 2;
		
		public static const DIRECTION_UP:int = 3;
		
		public static const DIRECTION_DOWN:int = 4;
		
		
		protected var _direction:int;
		
		protected var _isWalking:Boolean;
		
		protected var curFrame:int;
		
		protected var fps:int;
		
		protected var frameWidth:int;
		
		protected var frameHeight:int;
		
		protected var walkingBitmap:BitmapData;
		
		public function Character()
		{
			super();
		}
		
		public function setupCharacter( bitmapData:BitmapData,  fps:int ):void
		{
			frameWidth = bitmapData.width / FRAMES_PER_DIRECTION;
			
			frameHeight = bitmapData.height / DIRECTION_NUM;
			
			this.fps = fps;
			
			this._graphic = new Graphic( bitmapData, null );
			
			curFrame = 0;
			
			_isWalking = false;
			
			this.walkingBitmap = bitmapData;
			
		}
		
		override public function getGraphic():Graphic
		{
			var rect:Rectangle = null;
			
			if( isWalking )
			{
				rect = new Rectangle( curFrame * frameWidth, direction * frameHeight, frameWidth, frameHeight  );	
			}
			else
			{
				rect =  new Rectangle( 0, direction * frameHeight, frameWidth, frameHeight  );	
			}
			
			_graphic.rect = rect;
			
			return _graphic;
		}
		
		override public function onEnterFrame(dt:int):void
		{
			if( isWalking )
			{
				var frameOffset:int = int( Number( dt ) / 1000 * fps );
			
				curFrame = ( curFrame + frameOffset ) % FRAMES_PER_DIRECTION;
			}
			
		}
		
		public function turn( direction:int ):void
		{
			
		}
		
		public function move( x:int, y:int ):void
		{
			
		}
		
		
		public function get direction():int
		{
			return _direction;
		}
		
		public function get isWalking():Boolean
		{
			return _isWalking;
		}
		
		
		
		
	}
}